package com.tang.combine;

import org.apache.flink.calcite.shaded.org.checkerframework.checker.units.qual.C;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * 联合
 * 联合合流操作一次可以合并多条流
 * 联合操作的数据类型必须是一致的
 *
 * @author tang
 * @since 2023/6/9 12:00
 */
public class UnionDemo {

    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(new Configuration());
        env.setParallelism(1);

        DataStreamSource<Integer> source1 = env.fromElements(1, 2, 3);
        DataStreamSource<Integer> source2 = env.fromElements(11, 22, 33);
        DataStreamSource<String> source3 = env.fromElements("111", "222", "333");
        
        //DataStream<Integer> union = source1.union(source2).union(source3.map(Integer::valueOf));
        DataStream<Integer> union = source1.union(source2, source3.map(Integer::valueOf));
        
        union.print();
        
        env.execute();
    }
    
}
